<?php
/**
 * Created by PhpStorm.
 * User: allen_ios
 * Date: 17/9/12
 * Time: 下午4:36
 */

namespace Task\App\Healthscorebjhq;


use Task\App\Base\BuildBaseInfo;
use Task\Core\Base;

class AutoMakeDir extends Base
{
    private $mysql;
    private $accountId;

    public function __construct()
    {
        parent::__construct();

        $this->mysql = $this->selectDB('mysql');
        $this->accountId = $_SERVER['argv'][3];
    }

    //创建目录
    public function createDir()
    {
        $buildModel = new BuildBaseInfo($this->accountId);

        //文件路径数组
        $pathArr = array();

        //获取园区列表
        $communityList = $buildModel->getCommunityList();
        if (!$communityList) {
            exit('园区不能为空！');
        }

        //拼接园区、楼幢、楼层的路径数组
        foreach ($communityList as $community) {

            $buildList = $buildModel->getBuildListByCommId($community['community_id']);
            if (!$buildList) {
                continue;
            }

            foreach ($buildList as $build) {
                $floorList = $buildModel->getFloorListByBuildingId($build['building_id']);
                if (!$floorList) {
                    continue;
                }

                foreach ($floorList as $floor) {
                    $pathArr[] = $community['community_id'] . '/' . $build['building_id'] . '/' . $floor['floor_id'];
                }
            }
        }

        //创建"日期/园区id/楼幢id/楼层id"的目录
        $currDate = date('Ymd');
        foreach ($pathArr as $path) {
            $path = $currDate.'/'.$path;
            @mkdir($path,0755,true);
        }
    }
}